/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.wpi.first.wpilibj.team1662.commands;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStationLCD;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.team1662.RobotMap;

/**
 *
 * @author programmer
 */
public class Drive extends CommandBase {
    private boolean trigger = false;

    
    public Drive() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(drivetrain);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        drivetrain.tankDrive(0, 0);
        drivetrain.cheezit(0);
        drivetrain.pickup(0);
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute(){
        
        SmartDashboard.putNumber("Right Joystick: ", oi.getRightStick());
        SmartDashboard.putNumber("Left Joystick: ", oi.getLeftStick());
        SmartDashboard.putNumber("Left Motor 1: ", drivetrain.getLeftMotor());
        SmartDashboard.putNumber("Left Motor 2: ", drivetrain.getLeftMotor2());
        SmartDashboard.putNumber("Right Motor 1: ", drivetrain.getRightMotor());
        SmartDashboard.putNumber("Right Motor 2: ", drivetrain.getRightMotor2());
        
        oi.updateButton();
        drivetrain.tankDrive(oi.getRightStick(), oi.getLeftStick());        

        //Just saying, maybe you want to comment out these commands
        //in case it messes with things!
        if (RobotMap.limitSwitch4.get() == true && RobotMap.limitSwitch3.get() == true && RobotMap.limitSwitch2.get() == true && RobotMap.limitSwitch1.get() == true) {
            drivetrain.cheezit(oi.getConveyorThrottle());
        } else if (RobotMap.limitSwitch4.get() == trigger && RobotMap.tripNum == 4) {
            drivetrain.cheezit(0);
        } else if (RobotMap.limitSwitch3.get() == trigger && RobotMap.tripNum == 3) {
            drivetrain.cheezit(0);
        } else if (RobotMap.limitSwitch2.get() == trigger && RobotMap.tripNum == 2) {
            drivetrain.cheezit(0);
        } else if (RobotMap.limitSwitch1.get() == trigger && RobotMap.tripNum == 1) {
            drivetrain.cheezit(0);
        } else 
            drivetrain.cheezit(oi.getConveyorThrottle());
        
        drivetrain.pickup(oi.getPickupThrottle());
        
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser1, 1, ""+RobotMap.tripNum);
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser2, 1, ""+RobotMap.limitSwitch1.get());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser3, 1, ""+RobotMap.limitSwitch2.get());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser4, 1, ""+RobotMap.limitSwitch3.get());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser5, 1, ""+RobotMap.limitSwitch4.get());
        DriverStationLCD.getInstance().updateLCD();
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
        drivetrain.tankDrive(0, 0);
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        drivetrain.tankDrive(0, 0);
        drivetrain.cheezit(0);
        drivetrain.pickup(0);
    }
}